//
//  JFScrumCollectionCell.m
//  JobFree2.0
//
//  Created by xxcao on 2017/5/25.
//  Copyright © 2017年 Dale. All rights reserved.
//

#import "JFScrumCollectionCell.h"
#import "JFScrumModel.h"
#import "TeamOperatingView.h"
#import "NSString+JFCategory.h"

@implementation JFScrumCollectionCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.bottomConstraint.constant = minLineWidth;
    self.topConstraint.constant = minLineWidth;
    self.rightConstraint.constant = minLineWidth;
    self.leftConstraint.constant = minLineWidth;
    UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPressAction:)];
    longPress.minimumPressDuration = 0.6;
    [self.contentView addGestureRecognizer:longPress];
}

- (void)setModel:(JFScrumModel *)model {
    _model = model;
    NSArray *logoArr = [model.board_logo componentsSeparatedByString:@","];
    CGFloat r = [(NSString *)logoArr[0] floatValue];
    CGFloat g = [(NSString *)logoArr[1] floatValue];
    CGFloat b = [(NSString *)logoArr[2] floatValue];
    self.logoLabel.textColor = [UIColor colorWithRed:r green:g blue:b alpha:1.0];
    self.nameLabel.text = model.board_remark;
    self.authorLabel.text = model.user_name;
    
    self.topImg.hidden = model.is_top == 0 ? YES : NO;
    self.disturbImg.hidden = model.is_disturb == 0 ? YES : NO;
    
    if ([NSString isEnglishFirst:model.board_name]) {
        self.logoLabel.text = [[model.board_name substringToIndex:2] capitalizedString];
    } else {
        self.logoLabel.text = [model.board_name substringToIndex:1];
    }
    
    
    if (model.index % 2 == 0) {
        if (model.index == 0) {
            self.topImgV.hidden = NO;
        } else {
            self.topImgV.hidden = YES;
        }
        self.bottomImgV.hidden = NO;
        self.rightImgV.hidden = NO;
    } else {
        if (model.index == 1) {
            self.topImgV.hidden = NO;
        } else {
            self.topImgV.hidden = YES;
        }
        self.bottomImgV.hidden = NO;
    }
}

- (void)handleLongPressAction:(UILongPressGestureRecognizer *)sender {
    if (sender.state == UIGestureRecognizerStateBegan) {
        TeamOperateBlock toBlock = ^(TeamOperatingViewReturn returnType,TeamOperatingView *view) {
            if (returnType == TeamOperatingViewTop) {
                //置顶操作
                _model.is_top = (_model.is_top == 0) ? 1 : 0;
                if (self.clickBlock) {
                    self.clickBlock(_model, view, JFScrumCollectionCellClickTypeTop);
                }
                
            } else if (returnType == TeamOperatingViewDisableAlert) {
                //免打扰
                _model.is_top = (_model.is_top == 0) ? 1 : 0;
                if (self.clickBlock) {
                    self.clickBlock(_model, view, JFScrumCollectionCellClickTypeDistrub);
                }
            } else if (returnType == TeamOperatingViewLeave) {
                //退出或解散看板
                if (self.clickBlock) {
                    self.clickBlock(_model, view, JFScrumCollectionCellClickTypeExit);
                }
            }
        };
        TeamOperatingView *toView = [[TeamOperatingView alloc] initWithFrame:CGRectZero ReturnBlock:toBlock ImGroup:_model];
        [toView show];
        toView.removeBlock = ^(TeamOperatingView *view) {
            
        };
    }
}



@end
